package com.qianli.cashmama.product.facade.enums;

import org.apache.commons.lang3.StringUtils;

import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by xuyang on 2017/7/18.
 */
public enum PaybackPeriodUnitEnum {
    DAY("DAY", "days"), WEEK("WEEK", "weeks"), MONTH("MONTH", "months"), YEAR("YEAR", "years");

    private String code;

    private String name;

    PaybackPeriodUnitEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }


    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public static PaybackPeriodUnitEnum getByCode(String code) {
        if (StringUtils.isEmpty(code)) {
            return null;
        }
        code = code.toUpperCase();
        return PaybackPeriodUnitMapper.map.get(code);
    }

    private static class PaybackPeriodUnitMapper {
        private static ConcurrentHashMap<String, PaybackPeriodUnitEnum> map = new ConcurrentHashMap<>();

        static {
            for (PaybackPeriodUnitEnum item : PaybackPeriodUnitEnum.values()) {
                map.put(item.getCode(), item);
            }
        }
    }


}

